package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 30318
 * Date: 2023-05-21
 * Time: 12:22
 */
public class AddOperation implements IOPeration{

    public void work(BookList bookList){
        System.out.println("新增图书");
        System.out.println("请输入你要新增书籍的书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        System.out.println("请输入你要新增书籍的作者：");
        String author = scanner.nextLine();

        System.out.println("请输入你要新增书籍的价格：");
        int price = scanner.nextInt();

        scanner.nextLine();

        System.out.println("请输入你要新增书籍的类型：");
        String type = scanner.nextLine();

        Book book = new Book(name, author,price,type);

        //1.获取到当前可以存放书籍的位置
        int currentSize = bookList.getUsedSize();

        //2.将书籍放入指定位置
        bookList.setBooks(book,currentSize);

        //3.将书籍的有效个数+1
        bookList.setUsedSize(currentSize+1);
    }
}
